#!/bin/sh

MODE=$1
echo "MODE: $MODE"

if [[ "$MODE" != "stage" && "x$MODE" != "x" ]]; then
    echo "Only parameter 'stage' allowed"
    exit -1
fi 

password=$(cf_mongo_root_pwd)

if [[ "x$password" == "x" ]]; then
    echo "Not logged in into bosh credhub, please run 'bosh_credhub_login' before"
    exit -1
fi

if [ "$MODE" == "stage" ]; then
    echo "Login to STAGE mongodb"
    conn_string="mongodb://MongoRoot:${password}@10.3.16.23:27017,10.3.16.24:27017,10.3.16.25:27017/admin?replicaSet=rs0"
else
    echo "Login to PRODUCTION mongodb"
    conn_string="mongodb://MongoRoot:${password}@10.3.18.23:27017,10.3.18.24:27017,10.3.18.25:27017/admin?replicaSet=rs0"
fi

#conn_string="mongodb://MongoRoot:${password}@10.3.18.23:27017,10.3.18.24:27017,10.3.18.25:27017/admin?replicaSet=rs0"

echo "${conn_string}"
#docker run -it --rm --name mongocli --net=host mongo mongo ${conn_string}
mongo ${conn_string}
